package com.ytrsoft.utils;

import com.ytrsoft.bean.Action;
import com.ytrsoft.bean.IOType;
import com.ytrsoft.bean.Message;

public final class MsgKit {

    private MsgKit() {
        throw new UnsupportedOperationException();
    }

    public static Message create(String error) {
        Throwable t = new Exception(error);
        return create(t);
    }

    public static Message create(Throwable t) {
        Message msg = new Message();
        msg.setAction(Action.EXCEPTION);
        msg.setBody(t.getMessage());
        return msg;
    }

    public static Message create(Action action) {
        Message msg = new Message();
        msg.setAction(action);
        return msg;
    }

    public static Message create(IOType type, String body) {
        Message msg = new Message();
        msg.setAction(Action.OUTPUT);
        msg.setBody(body);
        msg.setType(type);
        return msg;
    }

    public static Message create(IOType type, String body, boolean hasNewLine) {
        Message msg = new Message();
        msg.setAction(Action.OUTPUT);
        msg.setBody(body);
        msg.setNewLine(hasNewLine);
        msg.setType(type);
        return msg;
    }

}
